package org.stone.project.common.utils;

import cn.hutool.core.util.IdUtil;

import java.util.Date;

/**
 * 请求id
 */
public class RequestIdUtil {
    private static ThreadLocal<String> requestIdHolder = new ThreadLocal<>();

    /**
     * 获取requestId
     * @return
     */
    public static String getRequestId(){
        String requestId = requestIdHolder.get();
        if (requestId == null) {
            requestId = IdUtil.getSnowflakeNextIdStr();
            requestIdHolder.set(requestId);
            return requestId;
        }
        return requestId;
    }

    /**
     * 时间清空
     * @return
     */
    public static void clear(){
        requestIdHolder.remove();
    }
}
